package flc.ast.adapter;

import android.graphics.Color;
import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyColorBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class ColorAdapter extends StkProviderMultiAdapter<MyColorBean> {

    public ColorAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(45));
        addItemProvider(new ColorProvider());
    }

    private class ColorProvider extends BaseItemProvider<MyColorBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_color;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyColorBean bean) {
            if (bean.getColor().equals("#FFFFFF")) {
                baseViewHolder.setImageResource(R.id.ivColorItemSel, R.drawable.icon_g);
                baseViewHolder.setVisible(R.id.ivColorItemWhite, true);
            } else {
                baseViewHolder.setImageResource(R.id.ivColorItemSel, R.drawable.icon_g1);
            }
            if (baseViewHolder.getAdapterPosition() == 0) {
                baseViewHolder.getView(R.id.ivColorItemColor).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.tvColorItemText).setVisibility(View.GONE);
            } else {
                baseViewHolder.getView(R.id.ivColorItemColor).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.tvColorItemText).setVisibility(View.VISIBLE);
                baseViewHolder.setBackgroundColor(R.id.tvColorItemText, Color.parseColor(bean.getColor()));
            }
            if (bean.isSelect()) {
                baseViewHolder.getView(R.id.ivColorItemSel).setVisibility(View.VISIBLE);
            } else {
                baseViewHolder.getView(R.id.ivColorItemSel).setVisibility(View.GONE);
            }
        }
    }
}
